<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="referrer" content="never">
		<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
		<title></title>
		<link rel="stylesheet" href="css/mui.min.css">
		<style type="text/css">
			.mui-preview-image.mui-fullscreen {
				position: fixed;
				z-index: 20;
				background-color: #000;
			}
			
			.mui-preview-header,
			.mui-preview-footer {
				position: absolute;
				width: 100%;
				left: 0;
				z-index: 10;
			}
			
			.mui-preview-header {
				height: 44px;
				top: 0;
			}
			
			.mui-preview-footer {
				height: 50px;
				bottom: 0px;
			}
			
			.mui-preview-header .mui-preview-indicator {
				display: block;
				line-height: 25px;
				color: #fff;
				text-align: center;
				margin: 15px auto 4;
				width: 70px;
				background-color: rgba(0, 0, 0, 0.4);
				border-radius: 12px;
				font-size: 16px;
			}
			
			.mui-preview-image {
				display: none;
				-webkit-animation-duration: 0s;
				animation-duration: 0s;
				-webkit-animation-fill-mode: both;
				animation-fill-mode: both;
			}
			
			.mui-preview-image.mui-preview-in {
				-webkit-animation-name: fadeIn;
				animation-name: fadeIn;
			}
			
			.mui-preview-image.mui-preview-out {
				background: none;
				-webkit-animation-name: fadeOut;
				animation-name: fadeOut;
			}
			
			.mui-preview-image.mui-preview-out .mui-preview-header,
			.mui-preview-image.mui-preview-out .mui-preview-footer {
				display: none;
			}
			
			.mui-zoom-scroller {
				position: absolute;
				display: -webkit-box;
				display: -webkit-flex;
				display: flex;
				-webkit-box-align: center;
				-webkit-align-items: center;
				align-items: center;
				-webkit-box-pack: center;
				-webkit-justify-content: center;
				justify-content: center;
				left: 0;
				right: 0;
				bottom: 0;
				top: 0;
				width: 100%;
				height: 100%;
				margin: 0;
				-webkit-backface-visibility: hidden;
			}
			
			.mui-zoom {
				-webkit-transform-style: preserve-3d;
				transform-style: preserve-3d;
			}
			
			.mui-slider .mui-slider-group .mui-slider-item img {
				width: auto;
				height: auto;
				max-width: 100%;
				max-height: 100%;
			}
			
			.mui-android-4-1 .mui-slider .mui-slider-group .mui-slider-item img {
				width: 100%;
			}
			
			.mui-android-4-1 .mui-slider.mui-preview-image .mui-slider-group .mui-slider-item {
				display: inline-table;
			}
			
			.mui-android-4-1 .mui-slider.mui-preview-image .mui-zoom-scroller img {
				display: table-cell;
				vertical-align: middle;
			}
			
			.mui-preview-loading {
				position: absolute;
				width: 100%;
				height: 100%;
				top: 0;
				left: 0;
				display: none;
			}
			
			.mui-preview-loading.mui-active {
				display: block;
			}
			
			.mui-preview-loading .mui-spinner-white {
				position: absolute;
				top: 50%;
				left: 50%;
				margin-left: -25px;
				margin-top: -25px;
				height: 50px;
				width: 50px;
			}
			
			.mui-preview-image img.mui-transitioning {
				-webkit-transition: -webkit-transform 0s ease, opacity 0s ease;
				transition: transform 0s ease, opacity 0s ease;
			}
			
			@-webkit-keyframes fadeIn {
				0% {
					opacity: 0;
				}
				100% {
					opacity: 1;
				}
			}
			
			@keyframes fadeIn {
				0% {
					opacity: 0;
				}
				100% {
					opacity: 1;
				}
			}
			
			@-webkit-keyframes fadeOut {
				0% {
					opacity: 1;
				}
				100% {
					opacity: 0;
				}
			}
			
			@keyframes fadeOut {
				0% {
					opacity: 1;
				}
				100% {
					opacity: 0;
				}
			}
			
			p img {
				max-width: 100%;
				height: auto;
			}
		</style>

		<style>
			#content img {
				width: 100%;
				height: auto;
			}
			
			.button {
				background-color: #4CAF50;
				border: none;
				color: white;
				padding: 15px 32px;
				text-align: center;
				text-decoration: none;
				display: inline-block;
				font-size: 14px;
				margin: 4px 2px;
				cursor: pointer;
				width: 50%;
				opacity: 0.4;
				right: 0px;
				bottom: 0px;
			}
		</style>
		<script type="text/javascript" src="js/jquery-2.1.0.js"></script>
		<script src="js/mui.min.js"></script>
		<!--<script src="js/mui.zoom.js"></script>
		<script src="js/mui.previewimage.js"></script>-->
		<script>
		</script>
		<script type="text/javascript">
			mui.init({
				gestureConfig: {
					longtap: true
				}
			});
			document.addEventListener('plusready', function() {
				//console.log("所有plus api都应该在此事件发生后调用，否则会出现plus is undefined。"

				$(document).ready(function() {
					var data;
					$.getJSON("data/870aa_katong.json", function(result) {
						data = result;
						//alert("load data.");
					});

					$("#bt").click(function() {
						//alert("nihao");
						var i = Math.round(Math.random() * (data.length - 1));
						$("#content").html(data[i][1]);
						$("img").each(function() {
							$(this).attr("data-preview-group", "1");
							$(this).attr("data-preview-src", "");
						});
						//mui.previewImage();
						window.scrollTo(0,0);  

						//

					});

				});
				document.addEventListener("longtap", function(event) {
					/**
					 * 获取目标节点的tagName
					 */
					var name = event.target.tagName;
					name = name.toLowerCase();
					/**
					 * 如果是图片，则弹出选择框决定是否下载；
					 */
					if(name === "img") {
						var imgUrl = event.target.src;
						console.log('图片地址：' + imgUrl);
						var suffix = cutImageSuffix(imgUrl);
						/**
						 * http://dev.dcloud.net.cn/mui/ui/#dialog
						 */
						mui.confirm("是否下载此图片", "确认下载？", ["下载", "不下"], function(event) {
							/**
							 * index从0开始
							 */
							var index = event.index;
							if(index == 0) {
								/**
								 * 创建下载任务
								 * http://www.html5plus.org/doc/zh_cn/downloader.html#plus.downloader.createDownload
								 */
								var downLoader = plus.downloader.createDownload(imgUrl, {
									method: 'GET',
									filename: '_downloads/image' + suffix
								}, function(download, status) {
									var fileName = download.filename;
									console.log('文件名:' + fileName);
									console.log('下载状态：' + status);
									/**
									 * 保存至本地相册
									 * http://www.html5plus.org/doc/zh_cn/gallery.html#plus.gallery.save
									 */
									plus.gallery.save(fileName, function() {
										/**
										 * 保存后，弹出对话框是否查看；
										 * http://dev.dcloud.net.cn/mui/ui/#dialog
										 */
										mui.toast("下载成功。");
									});
								});
								/**
								 * 开始下载任务
								 * http://www.html5plus.org/doc/zh_cn/downloader.html#plus.downloader.Download.start
								 */
								downLoader.start();
							}
						});
					}
				});

			});
			// 截取图片后缀用于重命名图片，防止%E5%85%89%E6%98%8E%E8%A1%8C编码的文件不被系统相册识别；
			function cutImageSuffix(imageUrl) {
				var index = imageUrl.lastIndexOf('.');
				return imageUrl.substring(index);
			}
		</script>
	</head>

	<body style="background-color: #808080">
		<div id="img-content-app" class="mui-content" style="background-color: #808080;width: 100%;">

			<div id="content" class="mui-content-padded" align="center" style="background-color: #808080;width: 100%;">
			</div>

		</div>
		<div id="dg" style="z-index: 9999; position: fixed ! important; right: 0px; bottom: 0px;">
			<button id="bt" class="button">开始</button>

		</div>
	</body>

</html>